package com.maybach.workflow.common.model;

import com.alibaba.fastjson.JSON;
import com.maybach.util.AssertUtil;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import java.io.Serializable;
import java.util.Date;

public class FlowApplyDO implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * This field corresponds to the database column wf_flow_apply.id
     */
    private Long id;

    /**
     * This field corresponds to the database column wf_flow_apply.attach_biz_type
     */
    private String attachBizType;

    /**
     * This field corresponds to the database column wf_flow_apply.attach_biz_id
     */
    private Long attachBizId;

    /**
     * This field corresponds to the database column wf_flow_apply.flow_biz_type
     */
    private String flowBizType;

    /**
     * This field corresponds to the database column wf_flow_apply.content
     */
    private String content;

    /**
     * This field corresponds to the database column wf_flow_apply.clazz
     */
    private String clazz;

    /**
     * This field corresponds to the database column wf_flow_apply.creator
     */
    private Long creator;

    /**
     * This field corresponds to the database column wf_flow_apply.state
     */
    private Integer state;

    /**
     * This field corresponds to the database column wf_flow_apply.attributes
     */
    private String attributes;

    /**
     * This field corresponds to the database column wf_flow_apply.gmt_create
     */
    private Date gmtCreate;

    /**
     * This field corresponds to the database column wf_flow_apply.gmt_modified
     */
    private Date gmtModified;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getAttachBizType() {
		return attachBizType;
	}

	public void setAttachBizType(String attachBizType) {
		this.attachBizType = attachBizType;
	}

	public Long getAttachBizId() {
		return attachBizId;
	}

	public void setAttachBizId(Long attachBizId) {
		this.attachBizId = attachBizId;
	}

	public String getFlowBizType() {
		return flowBizType;
	}

	public void setFlowBizType(String flowBizType) {
		this.flowBizType = flowBizType;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getClazz() {
		return clazz;
	}

	public void setClazz(String clazz) {
		this.clazz = clazz;
	}

	public Long getCreator() {
		return creator;
	}

	public void setCreator(Long creator) {
		this.creator = creator;
	}

	public Integer getState() {
		return state;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	public String getAttributes() {
		return attributes;
	}

	public void setAttributes(String attributes) {
		this.attributes = attributes;
	}

	public Date getGmtCreate() {
		return gmtCreate;
	}

	public void setGmtCreate(Date gmtCreate) {
		this.gmtCreate = gmtCreate;
	}

	public Date getGmtModified() {
		return gmtModified;
	}

	public void setGmtModified(Date gmtModified) {
		this.gmtModified = gmtModified;
	}


    public Object getContentObject() {
        if(null == content){
            return null;
        }
        try {
            return JSON.parseObject(content, Class.forName(clazz));
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }

    public void  setContentObject(Object content){
        AssertUtil.notNull(content, "content");
        this.clazz = content.getClass().getName();
        this.content = JSON.toJSONString(content);
    }


    @Override
    public String toString(){
        return ReflectionToStringBuilder.toString(this, ToStringStyle.DEFAULT_STYLE);
    }
}